/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.flexengine.math;

/**
 * @author Luann R. Athayde
 * @version 1.0
 * @since 1.0
 */
public class Point3D {
    
    private float x;
    private float y;
    private float z;

    public Point3D() {
        this(0f,0f,0f);
    }

    public Point3D(Point3D p) {
        if( p != null ) {
            this.x = p.x;
            this.y = p.y;
            this.z = p.z;
        }
        else {
            this.x = 0;
            this.y = 0;
            this.z = 0;
        }
    }

    public Point3D(float x, float y, float z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    
    public void move(float x, float y, float z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public void setLocation(Point3D p) {
        if( p == null ) return;
        x = p.x;
        y = p.y;
        z = p.z;
    }
    public void setLocation(float x, float y, float z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    public Point3D getLocation() {
        return new Point3D(x, y, z);
    }

    public void translate(float dx, float dy) {
        x += dx;
        y += dy;
    }
    
    public float getX() {
        return x;
    }

    public float getY() {
        return y;
    }

    public float getZ() {
        return z;
    }
    
    public float distanceSq(float x1, float y1, float z1, float x2, float y2, float z2) {
        x1 -= x2;
        y1 -= y2;
        z1 -= z2;
        return (x1 * x1 + y1 * y1 + z1 * z1);
    }
    public float distanceSq(float x, float y, float z) {
        return distanceSq(this.x, this.y, this.z, x, y, z);
    }

    public float distance(float x1, float y1, float z1, float x2, float y2, float z2) {
        x1 -= x2;
        y1 -= y2;
        z1 -= z2;
        return (float) Math.sqrt(x1 * x1 + y1 * y1 + z1 * z1);
    }
    
    public float distance(Point3D other) {
        return distance(other.x, other.y, other.z);
    }
    
    public float distance(float x, float y, float z) {
        return distance(this.x, this.y, this.z, x, y, z);
    }
    
    @Override
    protected Point3D clone() {
        return new Point3D(x, y, z);
    }
    
    @Override
    public boolean equals(Object obj) {
        if( obj != null && obj instanceof Point3D ) {
            Point3D tmp = (Point3D) obj;
            if( tmp.x == this.x && tmp.y == this.y && tmp.z == this.z )
                return true;
        }
        return false;
    }

    public boolean equals(Point3D p) {
        if( p != null ) {
            if(this.x == p.x && this.y == p.y && this.z == p.z) {
                return true;
            }
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        int hash = 3;
        hash = 53 * hash + Float.floatToIntBits(this.x);
        hash = 53 * hash + Float.floatToIntBits(this.y);
        hash = 53 * hash + Float.floatToIntBits(this.z);
        return hash;
    }

    
    @Override
    public String toString() {
        return "Point3D("+x+","+y+","+z+")";
    }
}
